<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/Loading.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/LodopFuncs.js"/>"></script>
<script>
	var dataLeft;

	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							url : "<c:url value='/quotationCompany/companyPeriodList.do'/>",
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '删除方案',
										iconCls : 'icon-add',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {

												$
														.ajax({
															async : false,
															url : "<c:url value='/quotationCompany/deleteCompanyPeriod.do'/>"
																	+ "?quotationId="
																	+ row[0]['quotationId']
																	+ "&companyId="
																	+ row[0]['companyId'],
															type : "post",
															data : {
																materType : 1
															},
															success : function(
																	data) {
																data = eval('('
																		+ data
																		+ ')');
																if (data.success) {
																	$.messager
																			.alert(
																					'系统提示',
																					'删除成功',
																					'info',
																					function() {
																						$(
																								'#'
																										+ listDisplayEId)
																								.datagrid(
																										'reload');
																					});
																}
															}
														});
											}

										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '下载方案',
										iconCls : 'icon-edit',
										handler : function() {

											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {

												$('#AddFoodForm2').form('submit',
								                        {
								                            url:'<c:url value='/quotationCompany/downCompanyPeriod.do'/>'+"?quotationId="+row[0]['quotationId'], //查询提交路径
								                            onSubmit:function()//提交按钮相应函数
								                            {
								                                return $('#AddFoodForm2').form('validate');
								                            },
								                            success:function(data){
								                                data = eval( "("+data+")" );
								                                if(data.success){
								                                    $.messager.alert("提示", "下载成功！", 'info');
								                                }
								                            },
								                            error:function(){
								                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
								                                return;
								                            }
								                        });
								                
											}
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '方案详细页面',
										iconCls : 'icon-redo',
										handler : function() {

											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var new_win = window
														.open(
																"<c:url value='/jsp/openIndexSun.jsp?url=/quotationCompany/preDetailCompanyPeriod.do'/>"
																		+ "?quotationId="
																		+ row[0]['quotationId'],
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");
												new_win.focus();
												$('#' + listDisplayEId)
														.datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid(
													'clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_add',
										text : '采用方案',
										iconCls : 'icon-add',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {

												$
														.ajax({
															async : false,
															url : "<c:url value='/quotationCompany/adoptCompanyPeriod.do'/>"
																	+ "?quotationId="
																	+ row[0]['quotationId']
																	+ "&companyId="
																	+ row[0]['companyId'],
															type : "post",
															data : {
																materType : 1
															},
															success : function(
																	data) {
																data = eval('('
																		+ data
																		+ ')');
																if (data.success) {
																	$.messager
																			.alert(
																					'系统提示',
																					'采用成功',
																					'info',
																					function() {
																						$(
																								'#'
																										+ listDisplayEId)
																								.datagrid(
																										'reload');
																					});
																}
															}
														});
											}
										}
									} ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});
	};

	function excelin() {
		$('#AddFoodForm')
				.form(
						'submit',
						{
							url : '<c:url value='/quotationCompany/importDetailCompanyPeriod.do'/>',
							onSubmit : function()//提交按钮相应函数
							{

								if (document.getElementById('companyId').value == 0) {
									alert("请选择公司！");
									return false;
								} else {
									return $('#AddFoodForm').form('validate');
								}
							},
							success : function(data) {
								data = eval('(' + data + ')');
								var msgsuccess = data.success + "";
								if (data.success) {
									Loading.Hide();
									$.messager.alert('系统提示', '导入成功', 'info',
											function() {
												$('listDisplay').datagrid(
														'reload');
											});
								} else {
									var message = "";
									if (data.msg == "msg001") {
										message = "文件不能为空,或者文件里没有材料，请选择文件填写材料。";
									} else if (data.msg == "msg003") {
										message = "第" + data.content
												+ "行材料id有问题！";
									} else if (data.msg == "msg004") {
										message = "第" + data.content
												+ "行材料价格有问题！";
									} else if (data.msg == "locked") {
										message = "正在提交中或其他人员提交中，请不要连续操作。";
									}
									$.messager.alert("提示", message, 'warning');
								}
							},
							error : function() {
								$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
								return;
							}
						});
	}
	function excelDown() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/supplier/exportSupperExcelCost.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				if (data.success) {
					$.messager.alert("提示", "下载成功！", 'info');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}
	$(document).ready(function() {
		document.getElementById('companyId').value = 0;
		document.getElementById('zzy').style.display = 'none';
		initList('listDisplay');
	});
	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioStore' />";
	}
	function formateQuotationFlag(value, rowData, rowIndex) {
		if (value == "1") {
			return "采用中";
		} else if (value == "0") {
			return "未采用";
		}
	}

	$(function() {
		//
		//获取data 数据
		$("#companyName").textbox({
			buttonText : '选择',
			iconAlign : 'left',
			editable : false,
			value : "无",
			multiline : true,
			height : '25px',
			onClickButton : function() {
				initDateLeft();
				showMsgLeft();
				ShowDiv();

				var left = $('#left').listbox();
				var items = left.getDatas();
				left.removeRange(items);

				/* var right = $('#right').listbox();
				var itemsr = right.getDatas();
				right.removeRange(itemsr);
				 */
				$('#left').listbox().reload({
					data : dataLeft,
					ajaxsettings : {
						data : {
							id : 'a'
						}
					}
				});
			}
		});
	});

	function initDateLeft() {
		$.ajax({
			async : false,
			url : "<c:url value='/quotationCompany/getAllCompanyJson.do'/>",
			type : "post",
			success : function(data) {
				if (typeof (data) == 'string' && data != '') {
					data = JSON.parse(data);
				}
				dataLeft = data.stringJson;
				if (typeof (dataLeft) == 'string' && dataLeft != '') {
					dataLeft = JSON.parse(dataLeft);
				}
			}
		});
	}
	function ShowDiv() {
		var Allwidth = '100%';
		var Allheight = '100%';
		document.getElementById('zzy').style.display = '';
		Loading.Show({
			width : Allwidth,
			height : Allheight
		});
	}
	//初始化showMsg
	function showMsgLeft() {
		$('#left').listbox({
			data : dataLeft,
			height : 300,
			width : 200,
			dndscope : 'demo',
			dnd : false,
			multiselect : true,
			selectchange : function(data) {
				if (data && data.length > 0) {
					$('#btnRight').attr('disabled', false);
				} else {
					$('#btnRight').attr('disabled', true);
				}
			}
		});
		$('#right').listbox({
			//data: data,
			height : 300,
			width : 200,
			dndscope : 'demo',
			dnd : true,
			multiselect : true
		});
		$('#btnRightAll').click(function() {
			var left = $('#left').listbox();
			var items = left.getDatas();
			left.clear();
			$('#right').listbox().addRange(items);
		});
		$('#btnLeftAll').click(function() {
			var right = $('#right').listbox();
			var items = right.getDatas();
			right.clear();
			$('#left').listbox().addRange(items);
		});
		$('#btnRight').click(function() {
			var left = $('#left').listbox();
			var items = left.getSelected();
			left.removeRange(items);
			$('#right').listbox().addRange(items);
		});
		$('#btnLeft').click(function() {
			var right = $('#right').listbox();
			var items = right.getSelected();
			right.removeRange(items);
			$('#left').listbox().addRange(items);
		});
		$('#btnRemove').click(function() {
			$('#right').listbox().removeRange([ {
				value : 2
			}, {
				value : 26
			} ]);
		});
		$('#btnSelect').click(function() {
			var selected = $('#right').listbox().getSelected();
			var msg = 'Selected count is: ' + selected.length;
			if (selected.length > 0) {
				msg += ', The first item text is: ' + selected[0].text;
			}
			msg += '.';
			alert(msg);
		});
		$('#btnGetItems').click(function() {
			var selected = $('#right').listbox('getDatas');
			alert('Items count is: ' + selected.length);
		});
		$('#btnSetSelection').click(function() {
			$('#left').listbox('setSelection', 1);
		});
		$('#select').click(function() {
			Loading.Hide();
			document.getElementById('zzy').style.display = 'none';

			var right = $('#right').listbox();
			var items = right.getDatas();
			var userNames = '';
			var userIds = '';
			if (items.length > 1) {
				alert("只能选取一位客户");
				return false;
			}

			if (items.length > 0) {
				for ( var e in items) {
					userNames = userNames + items[e].text + ',';
					userIds = userIds + items[e].value + ',';
				}
				userNames = userNames.substring(0, userNames.length - 1);
				userIds = userIds.substring(0, userIds.length - 1);
			}
			if (userNames != '' && userIds != '') {
				$('#companyName').textbox('setValue', userNames);
				document.getElementById('companyId').value = userIds;
			} else {
				$('#companyName').textbox('setValue', '无');
				document.getElementById('companyId').value = 0;
			}
		});
		$('#noselect').click(function() {
			Loading.Hide();
			document.getElementById('zzy').style.display = 'none';
		});
	}
</script>
</head>
<body>
	<table width="98%">
		<tr>
			<td>
				<form id="AddFoodForm" name="AddFoodForm" method="post"
					enctype="multipart/form-data">
					<div
						style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="新方案文件模块" iconCls="icon-add"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table cellpadding="5">
							<tr>
								<td>公司</td>
								<td><input
									style="word-wrap: break-word; word-break: break-all;"
									id="companyName" name="companyName"></input></td>
								<td><input class="easyui-validatebox" editable="false"
									id="companyId" name="companyId" type="hidden"></input></td>
								<td>文件路径</td>
								<td><input class="easyui-filebox" name="filename"
									data-options="required:true"></input></td>
								</td>
								<td><a href="#" style="width: 80px; height: 40px;"
									class="easyui-linkbutton" onclick="excelin()">导入新方案</a>
							</tr>
						</table>
					</div>
				</form>

			</td>
			<td>
                <form id="AddFoodForm2" name="AddFoodForm2" method="post"
                    enctype="multipart/form-data">
                    
                </form>

            </td>
		</tr>

	</table>
	<table width="98%">
		<tr>
			<td>
				<table id="listDisplay" title="公司列表" iconCls="icon-list"
					singleSelect="true" idField="quotationId" loadMsg="请稍候......"
					pagination="true" pageSize="20" pageList="[10,20,30,40,50]"
					sortName="shopId" rownumbers="true" sortOrder="asc">
					<thead>
						<tr>
							<th field="quotationId" width="25" align="center"
								formatter="formatRadio"></th>
							<th field="companyId" width="40" sortable="true" editor="text">公司id</th>
							<th field="companyName" width="140" sortable="true">公司名称</th>
							<th field="quotationDate" width="100" sortable="true">定价日期</th>
							<th field="quotationName" width="200" sortable="true">方案名称</th>
							<th field="quotationFlag" width="100" sortable="true"
								formatter="formateQuotationFlag">采用标记</th>
						</tr>
					</thead>
				</table>
			</td>
		</tr>
	</table>

	<div
		style='position: absolute; left: 40px; top: 40px; z-index: 101; background-color: #FFFFFF; border-radius: 10px; width: 550px;'
		id="zzy">
		<table align="center">
			<!-- <tr>
                <td colspan="3">
                    <form id="searchFormForShowCust" name="searchFormForShowCust"
                        method="post" accept-charset="UTF-8">
                        <div
                            style="height: auto; width: 470px; background: #fafafa; padding: 5px;"
                            class="easyui-panel" title="查询" iconCls="icon-search"
                            collapsible="true" minimizable="false" maximizable="false"
                            closable="false">
                            <table>
                                <tr>
                                    <td>省:</td>
                                    <td><input class="easyui-combobox" name="provinceShow"
                                        id="provinceShow" required="true" /></td>
                                    <td>市:</td>
                                    <td><input class="easyui-combobox" name="cityShow"
                                        id="cityShow" required="true" /></td>
                                </tr>
                                <tr>
                                    <td>区:</td>
                                    <td><input class="easyui-combobox" name="countryShow"
                                        id="countryShow" required="true" /></td>
                                    <td colspan="2"><a href="#" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-search'" style="width: 60px"
                                        onclick="searchInfoForShowCust()">查询</a></td>
                                </tr>
                            </table>
                        </div>
                    </form>
                </td>
            </tr> -->
			<tr>
				<td>
					<ul id="left">
					</ul>
				</td>
				<td><input type="button" value="&gt;&gt;" id="btnRightAll"
					style="width: 50px;" /><br /> <input type="button" value="&gt;"
					id="btnRight" style="width: 50px;" /><br /> <input type="button"
					value="&lt;" id="btnLeft" style="width: 50px;" /><br /> <input
					type="button" value="&lt;&lt;" id="btnLeftAll" style="width: 50px;" /></td>
				<td>
					<ul id="right">
					</ul>
				</td>
			</tr>
		</table>
		<table align="center">
			<tr>
				<!--  
                <td><input type="button" value="Add Item" id="btnAdd" /></td>
                <td><input type="button" value="Remove Item" id="btnRemove" /></td>
                <td><input type="button" value="Get Select" id="btnSelect" /></td>
                <td><input type="button" value="Get Items" id="btnGetItems" /></td>
                <td><input type="button" value="SetSelection (value equal to '1')" id="btnSetSelection" /></td>
                <td><input type="button" value="Reload" id="btnReload" /></td>
                -->
				<td><input type="button" value="取消" id="noselect" /></td>
				<td width="200px"></td>
				<td><input type="button" value="选择" id="select" /></td>

			</tr>
		</table>
	</div>
</body>
</html>